<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_51job_member_taocan',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['isdefault']=array('0'=>'否','1'=>'是');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'企业套餐'),
			array('op'=>'edit','title'=>'添加企业套餐'),
		),
		'list'=>array('data'=>'list','list'=>array(	
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'money','title'=>'金额','type'=>'string'),
			array('name'=>'looknum','title'=>'查看简历数','type'=>'string'),
			array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),				
		)),
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_51job_member_taocan',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	$return['status']=array('0'=>'禁用','1'=>'启用');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'套餐设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回企业套餐列表'),
		),
		'edit'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'money','title'=>'金额','type'=>'string'),
			array('name'=>'looknum','title'=>'查看简历数','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'switch'),			
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('title','money','looknum','status','paixu'),$postdata);
	$id=intval($postdata['id']);
	if($id){		
		pdo_update('jy_51job_member_taocan',$data,array('id'=>$id));
		exi('设置成功！','','goback');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_51job_member_taocan',$data);
		exi('添加成功！','','goback');
	}
}

if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的企业套餐！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_51job_member_taocan',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['ishot'])){
		pdo_update('jy_51job_member_taocan',array('ishot'=>intval($post['ishot'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_51job_member_taocan',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_51job_member_taocan',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>